﻿<UserControl x:Class="YAWD.UserControls.UcProvider"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:common="clr-namespace:YAWD.Utils"
             mc:Ignorable="d" Loaded="UserControl_Loaded" Name="ProviderControl"
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.InputBindings>
        <KeyBinding Command="common:Commands.SetWallPaper" Gesture="CTRL+S"></KeyBinding>
        <KeyBinding Command="common:Commands.Exclude" Gesture="CTRL+E"></KeyBinding>
        <KeyBinding Command="common:Commands.DeleteItem" Gesture="CTRL+D"></KeyBinding>
    </UserControl.InputBindings>
    <UserControl.CommandBindings>
        <CommandBinding Command="common:Commands.SetWallPaper"  Executed="OnSetWallPaper" />
        <CommandBinding Command="common:Commands.Exclude"  Executed="OnExclude"  />
        <CommandBinding Command="common:Commands.DeleteItem"  Executed="OnDelete"  />
    </UserControl.CommandBindings>
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <common:BitmapFrameConverter x:Key="BitmapFrameConverter" DecodePixelWidth="{x:Static SystemParameters.PrimaryScreenWidth}"/>
            <DataTemplate x:Key="CoverTemplate">
                <Control>
                    <Control.Template>
                        <ControlTemplate>
                            <Border Padding="1" CornerRadius="0" BorderThickness="0" x:Name="bd" Margin="5">
                                <Grid>
                                    <Image x:Name="imgPhoto" Margin="6" Width="200" Grid.Row="0" 
                                           Source="{Binding Mode=OneWay, Converter={StaticResource BitmapFrameConverter}}"  
                                           IsHitTestVisible="True" RenderOptions.BitmapScalingMode="HighQuality"/>
                                    <Button x:Name="btnWallPaper" Visibility="Collapsed" VerticalAlignment="Bottom" HorizontalAlignment="Right"
                                         ToolTip="Set as WallPaper" Command="common:Commands.SetWallPaper" CommandParameter="{Binding}">
                                        <Button.Template>
                                            <ControlTemplate>
                                                <Border Padding="2" CornerRadius="6" Background="LightGray" BorderBrush="Black" BorderThickness="1">
                                                    <Image Source="/YAWD;component/Images/image_accept.png" Height="32" RenderOptions.BitmapScalingMode="HighQuality" />
                                                </Border>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>
                                    <Button x:Name="btnExclude" Visibility="Collapsed" VerticalAlignment="Top" HorizontalAlignment="Left"
                                         ToolTip="Exclude from Wallpaper list" Command="common:Commands.Exclude" CommandParameter="{Binding}">
                                        <Button.Template>
                                            <ControlTemplate>
                                                <Border Padding="2" CornerRadius="6" Background="LightGray" BorderBrush="Black" BorderThickness="1">
                                                    <Image Source="/YAWD;component/Images/image_remove.png" Height="32" RenderOptions.BitmapScalingMode="HighQuality"/>
                                                </Border>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>
                                    <Button x:Name="btnDelete" Visibility="Collapsed" VerticalAlignment="Top" HorizontalAlignment="Right"
                                         ToolTip="Click to delete" Command="common:Commands.DeleteItem" CommandParameter="{Binding}">
                                        <Button.Template>
                                            <ControlTemplate>
                                                <Border Padding="2" CornerRadius="6" Background="LightGray" BorderBrush="Black" BorderThickness="1">
                                                    <Image Source="/YAWD;component/Images/image_delete.png" Height="32" RenderOptions.BitmapScalingMode="HighQuality"/>
                                                </Border>
                                            </ControlTemplate>
                                        </Button.Template>
                                    </Button>
                                </Grid>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter TargetName="bd" Property="Background" Value="{DynamicResource MouseOverColor}" />
                                    <Setter TargetName="bd" Property="BorderBrush" Value="Black" />
                                    <Setter TargetName="btnWallPaper" Property="Visibility" Value="Visible" />
                                    <Setter TargetName="btnDelete" Property="Visibility" Value="Visible" />
                                    <Setter TargetName="btnExclude" Property="Visibility" Value="Visible" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Control.Template>
                </Control>
            </DataTemplate>
            <Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Padding" Value="2,0,0,0"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <Border Margin="3" CornerRadius="0" x:Name="Bd" BorderBrush="{x:Null}" BorderThickness="0" 
                                    Background="Transparent" Padding="0" SnapsToDevicePixels="true">
                                <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected" Value="true">
                                    <Setter Property="Background" TargetName="Bd" Value="{x:Null}"/>
                                    <Setter Property="Foreground" Value="{x:Null}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

        </ResourceDictionary>
    </UserControl.Resources>
    <Expander ExpandDirection="Down" Margin="2,3" Name="ExpExpander" Expanded="Expander_Expanded" BorderBrush="#FFA0D8F0" BorderThickness="3"
              Collapsed="Expander_Collapsed">
        <Expander.Header >
            <Border Background="#FF41B1E1">
                <TextBlock Foreground="White" x:Name="TxtHeader" Width="{Binding ElementName=ExpExpander, Path=ActualWidth}"
                          HorizontalAlignment="Stretch" FontSize="{DynamicResource NormalFontSize}" FontFamily="Segoe UI" />
            </Border>
        </Expander.Header>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>

            <StackPanel Grid.Row="0" Orientation="Horizontal" Grid.ColumnSpan="3" Margin="20,5,0,0" >
                <TextBlock Text="{DynamicResource lblCurrentUrl}" FontWeight="Heavy" FontFamily="Segoe UI"/>
                <TextBlock Name="lblUrl" FontFamily="Segoe UI"/>
                <TextBlock Text="Last Update : " FontWeight="Heavy" Margin="10,0,0,0"/>
                <TextBlock Name="lblLastUpdated"/>
                <TextBlock Text="Last Image : " FontWeight="Heavy" Margin="10,0,0,0"/>
                <TextBlock Text="{Binding Path=lblCurrentImage, ElementName=ProviderControl, Mode=OneWay}"/>
            </StackPanel>

            <ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"
                KeyboardNavigation.TabNavigation="Cycle"
                BorderBrush="{x:Null}" Margin="5,0,0,0"
                ScrollViewer.VerticalScrollBarVisibility="Hidden" 
                VerticalAlignment="Top"  IsSynchronizedWithCurrentItem="True"
                ItemTemplate="{StaticResource CoverTemplate}" ItemContainerStyle="{StaticResource ListBoxItemStyle1}"
                ItemsSource="{Binding Path=lstImages, ElementName=ProviderControl, Mode=OneWay}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
            </ListBox>

            <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" Name="progressCol"></ColumnDefinition>
                    <ColumnDefinition Width="200"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <ProgressBar Height="20" Width="{Binding Path=Width, ElementName=progressCol}"  Name="progressBar" Margin="5" Grid.Row="0" Grid.Column="0"
                    Maximum="100" Minimum="0" Visibility="Collapsed"
                    Value="{Binding Path=PbarCurrent, ElementName=ProviderControl, Mode=OneWay}"/>
                <StackPanel Grid.Row="0" Grid.Column="1"  Orientation="Horizontal" HorizontalAlignment="Center">
                    <Button Name="btnCancel" Content="Stop" ToolTip="Stop Downloading" Width="80" Height="24"
                    Click="btnCancel_Click" Margin="5" Visibility="Collapsed"/>
                    <Button Name="btnGetAll" Content="{DynamicResource lblGetAll}" ToolTip="{DynamicResource ttpGetAll}" Width="80" Height="24"
                    Click="btnGetAll_Click" Margin="5"/>
                    <Button Name="btnUpdate" Content="{DynamicResource lblUpdate}" ToolTip="{DynamicResource ttpUpdate}" Width="80" Height="24"
                    Click="btnUpdate_Click" Margin="5"/>
                </StackPanel>
            </Grid>
        </Grid>
    </Expander>
</UserControl>
